﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Net.Sockets;
using System.IO;

namespace ConsoleApplication1
{
    class Client
    {
        TcpListener serverListen = null;
        TcpClient client = null;
        NetworkStream stream = null;
        public void TCPConnect(string address, Int32 port)
        {
            try
            {
                serverListen = new TcpListener(IPAddress.Parse(address), port);
                serverListen.Start();
                Console.Write("Waiting for a connection... ");
                client = serverListen.AcceptTcpClient();
                Console.WriteLine("Connected!");
                stream = client.GetStream();
            }
            catch (SocketException e)
            {
                Console.WriteLine("Socket Exception: {0}", e);
            }
        }

        public void TCPDisconnect()
        {
            this.serverListen.Stop();
        }

        public void TCPSend(string message)
        {
            byte[] convert = System.Text.Encoding.ASCII.GetBytes(message);
            this.stream.Write(convert, 0, convert.Length);
            Console.WriteLine("Sent: " + message);
        }

        public void TCPListen()
        {
            Byte[] bytes = new Byte[256];
            String data = null;
            while (true)
            {
                int i;
                while ((i = stream.Read(bytes, 0, bytes.Length)) != 0)
                {
                    data = System.Text.Encoding.ASCII.GetString(bytes, 0, i);
                    Console.WriteLine("Received: {0}", data);
                }
                client.Close();
            }
        }

        public void Rock()
        {
            Console.WriteLine("User has chosen Rock.");
        }

        public void Paper()
        {
            Console.WriteLine("User has chosen Paper.");
        }

        public void Scissors()
        {
            Console.WriteLine("User has chosen Scissors.");
        }
    }
}